{$CLEO .qa}
{$USE CLEO+}
{$USE Audio}
{$USE newOpcodes}
{$USE ini}

0000: NOP

script_name "DICGMQA"

// By ArtemQa146 and ScarButtCheeks

const
    left_man = 31@
    right_man = 30@
    midle_man = 29@
    progress = 25@
    coords_x = 24@
    coords_y = 23@
    coords_z = 22@
    angle_1 = 21@
    choice = 28@
    obj_1 = 27@
    render_L = 20@
    render_R = 19@
    render_M = 18@
    gang_check = 26@
    model_1 = 17@
    model_2 = 16@
    model_3 = 15@
    money_pickup = 14@
    timeq = 13@
end

0087: coords_x = 0@ // (float)
0087: coords_y = 1@ // (float)
0087: coords_z = 2@ // (float)
0087: angle_1 = 3@ // (float)
0085: gang_check = 4@ // (int)

if
    0E4D: random_percent 5@
then
else
    repeat
    wait 0
    until not locate_char_distance_to_coordinates $PLAYER_ACTOR pos coords_x coords_y coords_z radius 120.0
    0A93: terminate_this_custom_script
end

if
    gang_check == 7 // ballas
then
    model_1 = 102
    model_2 = 103
    model_3 = 104
end

if
    gang_check == 8 // groove
then
    model_1 = 105
    model_2 = 106
    model_3 = 107
end

if
    gang_check == 9 // Vagos
then
    model_1 = 108
    model_2 = 109
    model_3 = 110
end

if
    gang_check == 10 // San Fierro Rifa
then
    model_1 = 173
    model_2 = 174
    model_3 = 175
end
        
        repeat
        wait 0
        04ED: load_animation  "PedEventsMod"
        until 04EE:   animation "PedEventsMod" loaded

        model.Load(model_1)
        model.Load(model_2)
        model.Load(model_3)
        model.Load(1852)
        if
            not model.Available(model_1)
        then
            repeat
            wait 0
            model.Load(model_1)
            until model.Available(model_1)
        end
        if
            not model.Available(model_2)
        then
            repeat
            wait 0
            model.Load(model_2)
            until model.Available(model_2)
        end
        if
            not model.Available(model_3)
        then
            repeat
            wait 0
            model.Load(model_3)
            until model.Available(model_3)
        end
        if
            not model.Available(1852)
        then
            repeat
            wait 0
            model.Load(1852)
            until model.Available(1852)
        end
        038B: load_requested_models

        009A: left_man = create_actor_pedtype gang_check model model_1 at coords_x coords_y coords_z
        0173: set_actor left_man Z_angle_to angle_1
        0E24: fix_char left_man ground 1 brightness 1 and_fade_in 0
        0812: AS_actor left_man perform_animation "Stand_1" IFP "PedEventsMod" framedelta 8.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1  // versionB
        0E2E: create_render_object_to_char_bone left_man model 1852 bone 24 offset 0.1 0.05 0 rotation 0 0 0 store_to render_L

        04C4: store_coords_to 1@ 2@ 3@ from_actor left_man with_offset 1.0 1.0 0.0
        009A: midle_man = create_actor_pedtype gang_check model model_2 at 1@ 2@ 3@
        angle_1 += 90.0
        0173: set_actor midle_man Z_angle_to angle_1
        0E24: fix_char midle_man ground 1 brightness 1 and_fade_in 0
        0812: AS_actor midle_man perform_animation "Stand_1" IFP "PedEventsMod" framedelta 8.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1  // versionB
        0E2E: create_render_object_to_char_bone midle_man model 1852 bone 24 offset 0.1 0.05 0 rotation 0 0 0 store_to render_M

        04C4: store_coords_to 1@ 2@ 3@ from_actor left_man with_offset 0.0 2.0 0.0
        009A: right_man = create_actor_pedtype gang_check model model_3 at 1@ 2@ 3@
        0172: 1@ = actor left_man Z_angle
        1@ += 180.0
        0173: set_actor right_man Z_angle_to 1@
        0E24: fix_char right_man ground 1 brightness 1 and_fade_in 0
        0812: AS_actor right_man perform_animation "Stand_1" IFP "PedEventsMod" framedelta 8.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1  // versionB
        0E2E: create_render_object_to_char_bone right_man model 1852 bone 24 offset 0.1 0.05 0 rotation 0 0 0 store_to render_R
        
        04C4: store_coords_to 1@ 2@ 3@ from_actor left_man with_offset 0.0 1.0 0.0
        0E01: create_object_no_save 1852 at 1@ 2@ 3@ offset 0 ground 1 to obj_1
        0172: 1@ = actor left_man Z_angle
        0177: set_object obj_1 Z_angle_to 1@
        08D2: object obj_1 scale_model 0.0
        0382: set_object obj_1 collision_detection 0
        07F7: set_object obj_1 destructible 0
        0400: store_coords_to 1@ 2@ 3@ from_object obj_1 with_offset 0.0 0.0 0.03
        01BC: put_object obj_1 at 1@ 2@ 3@
        
        0E37: set_render_object_scale render_L 0.15 0.15 0.15
        0E37: set_render_object_scale render_M 0.15 0.15 0.15
        0E37: set_render_object_scale render_R 0.15 0.15 0.15
        0E31: set_render_object_visible render_L 0
        0E31: set_render_object_visible render_M 0
        0E31: set_render_object_visible render_R 0
        0E30: set_render_object_auto_hide render_L dead 1 weapon 1 car 1
        0E30: set_render_object_auto_hide render_M dead 1 weapon 1 car 1
        0E30: set_render_object_auto_hide render_R dead 1 weapon 1 car 1

        model.Destroy(1852)
        model.Destroy(model_1)
        model.Destroy(model_2)
        model.Destroy(model_3)

        timera = 0
        choice = 0
        progress = 0
        timeq = 3000

        wait 500

        repeat
        wait 0
        if and
            056D:   actor left_man defined
            056D:   actor right_man defined
            056D:   actor midle_man defined
            03CA:   object obj_1 exists
        then

            //     
            080E: get_actor left_man ped_event_to 1@
            0E40: get_current_hour 2@
            if or
                0118:   actor left_man dead
                not locate_char_distance_to_char $player_actor char left_man radius 150.0
                not $ACTIVE_INTERIOR == 0
                not is_char_script_controlled left_man
                1@ == 49
                1@ == 9
                2@ < 7
                2@ > 18
            then
                break
            end

            080E: get_actor right_man ped_event_to 1@
            if or
                0118:   actor right_man dead
                not locate_char_distance_to_char $player_actor char right_man radius 150.0
                not is_char_script_controlled right_man
                1@ == 49
                1@ == 9
            then
                break
            end

            080E: get_actor right_man ped_event_to 1@
            080E: get_actor left_man ped_event_to 2@
            if or
                1@ == 15
                1@ == 31
                1@ == 59
                2@ == 15
                2@ == 31
                2@ == 59
            then
                break
            end

            080E: get_actor midle_man ped_event_to 1@
            if or
                0118:   actor midle_man dead
                not locate_char_distance_to_char $player_actor char midle_man radius 150.0
                not is_char_script_controlled midle_man
                1@ == 49
                1@ == 9
            then
                break
            end
            
            //      
            if or
                051A:   actor midle_man damaged_by_actor $PLAYER_ACTOR
                051A:   actor right_man damaged_by_actor $PLAYER_ACTOR
                051A:   actor left_man damaged_by_actor $PLAYER_ACTOR
            then
                gosub @Attack
                break
            end

            if or
                0457:   player $PLAYER_CHAR aiming_at_actor left_man
                0457:   player $PLAYER_CHAR aiming_at_actor right_man
                0457:   player $PLAYER_CHAR aiming_at_actor midle_man
            then
                0E83: get_current_char_weaponinfo $PLAYER_ACTOR store_to 1@
                0E89: get_weaponinfo_fire_type 1@ store_to 2@ //     
                if or
                    2@ == 1 //  
                    2@ == 3 //   (  ..)
                then
                    gosub @Attack
                    break
                end
            end
            
            if or
                progress > 0
                0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos coords_x coords_y coords_z radius 30.0
            then


                //     
                if
                    not gang_check == 8
                then
                    04C4: store_coords_to 1@ 2@ 3@ from_actor midle_man with_offset 0.0 1.0 0.0
                    if
                        0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos 1@ 2@ 3@ radius 0.5
                    then
                        if
                            timerb > 1000
                        then
                            0AC1: 1@ = load_audio_stream_with_3d_support "SQ/DontStepDice.mp3" // IF and SET
                            0AC4: link_3d_audio_stream 1@ to_actor midle_man
                            0AAD: set_audio_stream 1@ state 1
                            0ABC: set_audio_stream 1@ volume 1.0
                            wait 2000
                            0AAE: remove_audio_stream 1@
                            if and
                                056D:   actor left_man defined
                                056D:   actor right_man defined
                                056D:   actor midle_man defined
                            then
                                gosub @Attack
                            end
                            break
                        end
                    else
                        timerb = 0
                    end
                end

                //    
                if and
                    progress == 0
                    gang_check == 8
                    03EE:   player $PLAYER_CHAR controllable
                then
                    gosub @Text_box_remove_2
                    if
                        0EE4: locate_char_distance_to_char $PLAYER_ACTOR char midle_man radius 6.0
                    then
                        timeq = 6000
                        04C4: store_coords_to 1@ 2@ 3@ from_actor midle_man with_offset 0.0 2.1 0.0
                        if
                            0102:   actor $PLAYER_ACTOR in_sphere 1@ 2@ 3@ radius 0.6 0.6 1.0 sphere 1 stopped_on_foot
                        then
                            if
                                010A:   player $PLAYER_CHAR money > 49
                            then
                                if
                                    8A2A:   not text_box 'dice1' displayed
                                then
                                    0512: show_permanent_text_box 'dice1'  // If your health reaches zero, you will pass out and you will be treated at the local medical center.
                                end
                            else
                                if
                                    8A2A:   not text_box 'dice2' displayed
                                then
                                    0512: show_permanent_text_box 'dice2'  // If your health reaches zero, you will pass out and you will be treated at the local medical center.
                                end
                            end

                            if and
                                progress == 0
                                010A:   player $PLAYER_CHAR money > 49
                                00E1:   player 0 pressed_key 15
                            then
                                07CC: set_player $PLAYER_CHAR can_enter_exit_vehicles 0
                                04C4: store_coords_to 2@ 3@ 4@ from_actor midle_man with_offset 0.0 0.0 0.0
                                04C4: store_coords_to 5@ 6@ 7@ from_actor $PLAYER_ACTOR with_offset 0.0 0.0 0.0
                                0E27: get_angle_from_two_coords 5@ 6@ and 2@ 3@ to 4@
                                0173: set_actor $PLAYER_ACTOR Z_angle_to 4@
                                06AB: set_actor $PLAYER_ACTOR all_weapons_hidden 1
                                0812: AS_actor $PLAYER_ACTOR perform_animation "DicePlay" IFP "PedEventsMod" framedelta 2.0 loopA 0 lockX 0 lockY 0 lockF 0 time -1
                                progress = 100
                                08D2: object obj_1 scale_model 0.0
                                timerb = 0
                                gosub @Text_box_remove
                                wait 300
                            end

                        else
                            gosub @Text_box_remove
                        end
                    else
                        timeq = 3000
                        gosub @Text_box_remove
                    end
                else
                    timeq = 3000
                    gosub @Text_box_remove
                    if
                        not locate_char_distance_to_char $PLAYER_ACTOR char midle_man radius 6.0
                    then
                        gosub @Text_box_remove_2
                    end
                end

                //     
                if
                    progress == 100
                then
                    if
                        0611:   actor $PLAYER_ACTOR performing_animation "DicePlay"
                    then
                        0613: 1@ = actor $PLAYER_ACTOR animation "DicePlay" time
                        if
                            1@ > 0.9
                        then
                            progress = 102 // 
                            08D2: object obj_1 scale_model 0.15
                            0172: 2@ = actor left_man Z_angle
                            0209: 1@ = random_int_in_ranges 1 3
                            if 1@ == 1
                            then 0453: set_object obj_1 XY_rotation 0.0 0.0 angle 2@
                            end
                            if 1@ == 2
                            then 0453: set_object obj_1 XY_rotation 90.0 0.0 angle 2@
                            end
                            if 1@ == 1
                            then progress = 103 // 
                            end
                            07CC: set_player $PLAYER_CHAR can_enter_exit_vehicles 1
                        end
                    else
                        07CC: set_player $PLAYER_CHAR can_enter_exit_vehicles 1
                    end
                end

                if
                    progress == 102 // 
                then
                    00BA: show_text_styled GXT "NOWIN" time 2000 style 5  // Beefy Baron
                    0812: AS_actor $PLAYER_ACTOR perform_animation "DicePlayL" IFP "PedEventsMod" framedelta 2.0 loopA 0 lockX 0 lockY 0 lockF 0 time -1
                    0615: define_AS_pack_begin 5@
                    0812: AS_actor -1 perform_animation "DicePlayW" IFP "PedEventsMod" framedelta 2.0 loopA 0 lockX 0 lockY 0 lockF 0 time -1
                    0812: AS_actor -1 perform_animation "Stand_1" IFP "PedEventsMod" framedelta 2.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1
                    0616: define_AS_pack_end 5@
                    0618: assign_actor midle_man to_AS_pack 5@
                    061B: remove_references_to_AS_pack 5@
                    progress = 104
                    0109: player $PLAYER_CHAR money += -50
                    wait 500
                    continue
                end

                if
                    progress == 104 // 
                then
                    if and
                        8611:   actor $PLAYER_ACTOR performing_animation "DicePlayL"
                        0611:   actor midle_man performing_animation "Stand_1"
                    then
                        progress = 0
                        timera = 0
                        03E6: remove_text_box
                        continue
                    end
                end

                if
                    progress == 103 // 
                then
                    01E3: show_text_1number_styled GXT 'WINNER' number 50 time 2000 style 5  // NEW HIGH SCORE!!~n~~w~~1~
                    0812: AS_actor $PLAYER_ACTOR perform_animation "DicePlayW" IFP "PedEventsMod" framedelta 2.0 loopA 0 lockX 0 lockY 0 lockF 0 time -1
                    0615: define_AS_pack_begin 5@
                    0812: AS_actor -1 perform_animation "DicePlayL" IFP "PedEventsMod" framedelta 2.0 loopA 0 lockX 0 lockY 0 lockF 0 time -1
                    0812: AS_actor -1 perform_animation "Stand_1" IFP "PedEventsMod" framedelta 2.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1
                    0616: define_AS_pack_end 5@
                    0618: assign_actor midle_man to_AS_pack 5@
                    061B: remove_references_to_AS_pack 5@
                    progress = 105
                    0109: player $PLAYER_CHAR money += 50
                    wait 500
                    continue
                end

                if
                    progress == 105 // 
                then
                    if and
                        8611:   actor $PLAYER_ACTOR performing_animation "DicePlayW"
                        0611:   actor midle_man performing_animation "Stand_1"
                    then
                        progress = 0
                        timera = 0
                        03E6: remove_text_box
                        continue
                    end
                end


                //     
                if and
                    001D:   timera > timeq  // (int)
                    progress == 0
                then
                    0615: define_AS_pack_begin 5@
                    0812: AS_actor -1 perform_animation "DicePlay" IFP "PedEventsMod" framedelta 2.0 loopA 0 lockX 0 lockY 0 lockF 0 time -1
                    0812: AS_actor -1 perform_animation "Stand_1" IFP "PedEventsMod" framedelta 4.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1
                    0616: define_AS_pack_end 5@
                    0618: assign_actor midle_man(choice,1i) to_AS_pack 5@
                    061B: remove_references_to_AS_pack 5@
                    progress = 1
                    08D2: object obj_1 scale_model 0.0
                    0E31: set_render_object_visible render_M(choice,1i) 1
                    wait 300
                    timera = 0
                    continue
                end

                if and
                    timera > 500
                    progress == 1
                then
                    if
                        0611:   actor midle_man(choice,1i) performing_animation "DicePlay"
                    then
                        0613: 1@ = actor midle_man(choice,1i) animation "DicePlay" time
                        if
                            1@ > 0.8
                        then
                            0E31: set_render_object_visible render_M(choice,1i) 0
                            progress = 2 // 
                            08D2: object obj_1 scale_model 0.15
                            0172: 2@ = actor left_man Z_angle
                            0209: 1@ = random_int_in_ranges 1 6
                            if 1@ == 1
                            then 0453: set_object obj_1 XY_rotation 0.0 0.0 angle 2@
                            end
                            if 1@ == 2
                            then 0453: set_object obj_1 XY_rotation 90.0 0.0 angle 2@
                            end
                            if 1@ == 3
                            then 0453: set_object obj_1 XY_rotation 0.0 90.0 angle 2@
                            end
                            if 1@ == 4
                            then 0453: set_object obj_1 XY_rotation 180.0 0.0 angle 2@
                            end
                            if 1@ == 5
                            then 0453: set_object obj_1 XY_rotation 0.0 180.0 angle 2@
                            end
                            if 1@ == 1
                            then progress = 3 // 
                            end
                        end
                    else
                        progress = 2
                        08D2: object obj_1 scale_model 0.15
                    end
                end

                if
                    progress == 2
                then
                    if
                        0611:   actor midle_man(choice,1i) performing_animation "Stand_1"
                    then
                        progress = 0
                        choice += 1 //  
                        if choice >= 3
                        then choice = 0
                        end
                        timera = 0
                        continue
                    end
                end

                if
                    progress == 3 // 
                then
                    if
                        0611:   actor midle_man(choice,1i) performing_animation "Stand_1"
                    then
                        // 
                        0615: define_AS_pack_begin 5@
                        0812: AS_actor -1 perform_animation "DicePlayW" IFP "PedEventsMod" framedelta 2.0 loopA 0 lockX 0 lockY 0 lockF 0 time -1
                        0812: AS_actor -1 perform_animation "Stand_1" IFP "PedEventsMod" framedelta 2.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1
                        0616: define_AS_pack_end 5@
                        0618: assign_actor midle_man(choice,1i) to_AS_pack 5@
                        061B: remove_references_to_AS_pack 5@

                        if
                            not gang_check == 8 //   ,    
                        then
                            04C4: store_coords_to 1@ 2@ 3@ from_actor midle_man(choice,1i) with_offset 0.0 0.7 -0.7
                            0209: 4@ = random_int_in_ranges 20 100
                            02E1: money_pickup = create_cash_pickup 4@ at 1@ 2@ 3@ permanence_flag 0
                        end

                        choice += 1
                        if choice >= 3
                        then choice = 0
                        end

                        // 
                        0615: define_AS_pack_begin 5@
                        0812: AS_actor -1 perform_animation "DicePlayL" IFP "PedEventsMod" framedelta 2.0 loopA 0 lockX 0 lockY 0 lockF 0 time -1
                        0812: AS_actor -1 perform_animation "Stand_1" IFP "PedEventsMod" framedelta 2.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1
                        0616: define_AS_pack_end 5@
                        0618: assign_actor midle_man(choice,1i) to_AS_pack 5@
                        061B: remove_references_to_AS_pack 5@

                        choice -= 1
                        if choice < 0
                        then choice = 2
                        end

                        timera = 0
                        progress = 4
                        wait 300
                        continue
                    end
                end

                if and
                    timera > 1000
                    progress == 4
                then
                    if
                        0611:   actor midle_man(choice,1i) performing_animation "Stand_1"
                    then
                        if
                            not gang_check == 8 //   ,    
                        then
                            if
                                09D1:   pickup money_pickup created
                            then
                                0215: destroy_pickup money_pickup
                            end
                        end

                        progress = 0
                        choice += 1
                        if choice >= 3
                        then choice = 0
                        end
                        timera = 0
                        continue
                    else
                        if
                            not gang_check == 8 //   ,    
                        then
                            if
                                09D1:   pickup money_pickup created
                            then
                                if
                                    0214:   pickup money_pickup picked_up //   ,  
                                then
                                    gosub @Attack
                                    break
                                end
                            end
                        end
                    end
                end
                
            end

        else
            break
        end

        until not player.Defined(0)
        gosub @Text_box_remove
        gosub @Text_box_remove_2
        if
            not gang_check == 8
        then
            if
                09D1:   pickup money_pickup created
            then
                0215: destroy_pickup money_pickup
            end
        end
        if
            progress > 100
        then
            07CC: set_player $PLAYER_CHAR can_enter_exit_vehicles 1
        end
        if 056D:   actor left_man defined
        then 01C2: remove_references_to_actor left_man // Like turning an actor into a random pedestrian
        end
        if 056D:   actor right_man defined
        then 01C2: remove_references_to_actor right_man // Like turning an actor into a random pedestrian
        end
        if 056D:   actor midle_man defined
        then 01C2: remove_references_to_actor midle_man // Like turning an actor into a random pedestrian
        end
        if 03CA:   object obj_1 exists
        then 01C4: remove_references_to_object obj_1 // This object will now disappear when the player looks away
        end
        04EF: release_animation "PedEventsMod"
        
        repeat
        wait 0
        until not locate_char_distance_to_coordinates $PLAYER_ACTOR pos coords_x coords_y coords_z radius 100.0

        wait 60000

0A93: terminate_this_custom_script

:Attack
if
    not gang_check == 8
then
    01C2: remove_references_to_actor right_man // Like turning an actor into a random pedestrian
    if 056D:   actor right_man defined
    then 05E2: AS_actor right_man kill_actor $PLAYER_ACTOR
    end
    01C2: remove_references_to_actor left_man // Like turning an actor into a random pedestrian
    if 056D:   actor left_man defined
    then 05E2: AS_actor left_man kill_actor $PLAYER_ACTOR
    end
    01C2: remove_references_to_actor midle_man // Like turning an actor into a random pedestrian
    if 056D:   actor midle_man defined
    then 05E2: AS_actor midle_man kill_actor $PLAYER_ACTOR
    end
end
return

:Text_box_remove
if or
    0A2A:   text_box 'dice1' displayed
    0A2A:   text_box 'dice2' displayed
then
    03E6: remove_text_box
end
return

:Text_box_remove_2
if or
    0A2A:   text_box 'dice3' displayed
    0A2A:   text_box 'dice4' displayed
then
    03E6: remove_text_box
end
return